using System;

namespace DataBroker.Criteria
{
    /// <summary>
    /// Operators used for field comparison on searches.
    /// </summary>
    [Serializable]
    public class Operator 
    {

        /// <summary>
        /// Internal flag describing which operator this is.
        /// </summary>
        private int searchOperator;


        /// <summary>
        /// Default Constructor
        /// </summary>
        public Operator() 
        {

        }

        private Operator(int oper) 
        {
            searchOperator = oper;
        }


        /// <summary>
        /// Equal operator (=)
        /// </summary>
        public static readonly Operator Equal         = new Operator(1);
        /// <summary>
        /// D2Bk Like operator
        /// </summary>
        static public readonly Operator Like          = new Operator(2);
        /// <summary>
        /// D2Bk NOT Equal operator
        /// </summary>
        static public readonly Operator NotEqual     = new Operator(3);
        /// <summary>
        /// D2Bk LESS THAN operator
        /// </summary>
        static public readonly Operator LessThan     = new Operator(4);
        /// <summary>
        /// D2Bk LESS THAN Or Equal operator
        /// </summary>
        static public readonly Operator LessEqual    = new Operator(5);
        /// <summary>
        /// D2Bk GREATER THAN operator
        /// </summary>
        static public readonly Operator GreaterThan  = new Operator(6);
        /// <summary>
        /// D2Bk GREATER THAN Or Equal operator
        /// </summary>
        static public readonly Operator GreaterEqual = new Operator(7);
        /// <summary>
        /// D2Bk NOT Like operator
        /// </summary>
        static public readonly Operator NotLike      = new Operator(8);
        /// <summary>
        /// D2Bk In operator
        /// </summary>
        static public readonly Operator In            = new Operator(9);
        /// <summary>
        /// D2Bk IS Null operator
        /// </summary>
        static public readonly Operator IsNull       = new Operator(10);
        /// <summary>
        /// D2Bk IS NOT Null operator
        /// </summary>
        static public readonly Operator IsNotNull   = new Operator(11);
        /// <summary>
        /// D2Bk Null operator
        /// </summary>
        static public readonly Operator Null          = new Operator(12);
        /// <summary>
        /// D2Bk In operator
        /// </summary>
        static public readonly Operator NotIn            = new Operator(13);
        /// <summary>
        /// ORACLE_SEQUENCE operator
        /// </summary>
        public static readonly Operator ORACLE_SEQUENCE    = new Operator(14);

        /// <summary>
        /// Converts operator from string to Operator type
        /// </summary>
        /// <param name="op">string with operator name</param>
        /// <returns></returns>
        public static Operator OperatorFromString(string op)
        {
            switch (op)
            {
                case "Equal":
                    return Equal;
                case "NotEqual":
                    return NotEqual;
                case "LessThan":
                    return LessThan;
                case "Like":
                    return Like;
                case "LessEqual":
                    return LessEqual;
                case "GreaterThan":
                    return GreaterThan;
                case "NotLike":
                    return NotLike;
                case "GreaterEqual":
                    return GreaterEqual;
                case "In":
                    return In;
                case "IsNull":
                    return IsNull;
                case "IsNotNull":
                    return IsNotNull;
                case "Null":
                    return Null;
                case "NotIn":
                    return NotIn;
                case "ORACLE_SEQUENCE":
                    return ORACLE_SEQUENCE;
            }
            return Equal;
        }

        /// <summary>
        /// Returns the current value of the comparison operator. 
        /// </summary>
        /// <returns>Current value of the comparison operator. </returns>
        public override String ToString() 
        {
            switch( searchOperator ) 
            {
                case 1:
                    {
                        return "=";
                    }
                case 2:
                    {
                        return "LIKE";
                    }
                case 3:
                    {
                        return "<>";
                    }
                case 4:
                    {
                        return "<";
                    }
                case 5:
                    {
                        return "<=";
                    }
                case 6:
                    {
                        return ">";
                    }
                case 7:
                    {
                        return ">=";
                    }
                case 8:
                    {
                        return "NOT LIKE";
                    }
                case 9:
                    {
                        return "IN";
                    }
                case 10:
                    {
                        return "IS NULL";
                    }
                case 11:
                    {
                        return "IS NOT NULL";
                    }
                case 12:
                    {
                        return "NULL";
                    }
                case 13:
                    {
                        return "NOT IN";
                    }
                case 14:
                    {
                        return " ";
                    }
                default:
                    {
                        return "UNKNOWN";
                    }
            }
        } // END OF toString
    }
}